/**
 * 功能描述 卡片
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper")
	var Form = require("form");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");	
	var enmu=require("enums");
	var formTpl = require("../assets/tpl/formTwoTpl.tpl");
	
    var instance = {
        initComponent: function (params,widget) {
        	var form=new Form({
       		 show:false,
        	 parentNode:"#visit",
	  			 model:{
	  			 	defaultButton:false,
					id:"visitRecord",
					layout : formTpl,
					items:[{
						name:"pkCustomer",
						type:"hidden"
					},{
						name:"customerVersion",
						type:"hidden",
						defaultValue:"0"
					},{
						name:"pkCustomerVisitRecord",
						type:"hidden",
					},{
						name:"version",
						type:"hidden",
						defaultValue:"0"
					},{
						name:"organization",
					    type:"hidden",
					    defaultValue:activeUser.organization.pkOrganization
					},{
						name:"type",
						type:"hidden",
					},{
						name:"recordType",
						type:"hidden",
						defaultValue:"Return"
					},{
						name:"personalInfo.pkPersonalInfo",
						type:"hidden"
					},{
						name:"personalInfo.version",
						type:"hidden",
						defaultValue:"0"
					},{
						name:"personalInfo.name",
						label:"姓名",
						validate:["required"]
					},{
						name:"personalInfo.sex",
						label:"性别",
						type:"radio",
					    list:[{
					    	key:"Male",
							value:"男"
						},{
							key:"Female",
							value:"女"
			            }],
						defaultValue:"Male",
						validate:["required"]
					},{
						name:"personalInfo.idNumber",
						label:"身份证号",
						validate:["required"],
						exValidate: function(value){
							if(value.match(/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/)==false){
								return "身份证号格式错误";
							}else{
								return true;
							}
						}
					},{
						name:"personalInfo.mobilePhone",
						label:"联系电话",
						exValidate: function(value){
							if(value.length>11){
								return "号码限制11位";
							}else{
								return true;
							}
						},
						validate:["required"]
					},{
						name:"personalInfo.birthday",
						label:"生日",
						type:"date",
						validate:["required"]
					},{
						name:"joinOtherOrg",
						label:"加入其他机构",
						type:"radio",
					    list:[{
					    	key:"true",
							value:"是"
						},{
							key:"false",
							value:"否"
			            }],
						defaultValue:"true",
						validate:["required"]
					},{
						name:"wechat",
						label:"微信",
					},{
						name:"qq",
						label:"QQ",
					},{
						name:"personalInfo.electronicMail",
						label:"E-MAIL",
					},{
						name:"personalInfo.houseRegister",
						label:"省/市/区（县）",
						type:"place",
						validate:["required"],
						"break": true
					},{
						name:"zipCode",
						label:"邮编",
						type:"text",
						exValidate: function(value){
							var re= /^[1-9][0-9]{5}$/
							if(re.test(value)){
								return true;
							}else{
								return "邮编格式错误";
							}
						},
					},{
						name:"personalInfo.address",
						label:"详细地址",
						type:"text",
						validate:["required"],
						"break": true
					},{
						name:"product",
						label:"意向产品",
						type:"select",
						key:"pkProduct",
						value:"name",
						params:function(){
							return {
								fetchProperties:"pkProduct,name"
							};
						},
						url:"api/product/query",
						validate:["required"]
					},{
						name:"productType",
						label:"产品类型",
						type:"select",
						key:"pkProductType",
						value:"name",
						lazy:true,
						url:"api/producttype/query",
						validate:["required"]
					},{
						name:"intention",
						label:"意向",
						type:"select",
						options:enmu["com.eling.elcms.travel.model.Intention"],
						validate:["required"]
					},{
						label:"来访时间",
						name:"visitDate",
 						type:"date",
 						mode:"YYYY-MM-DD HH:mm",
 						defaultValue:moment().format("YYYY-MM-DD HH:mm"),
 						validate:["required"]
					},{
						label : "回访提醒时间",
						name : "visitRemindDate",
						type:"date",
 						mode:"YYYY-MM-DD",
 						validate:["required"]
					},{
						label:"访问方式",
						name:"visitWay",
						type:"select",
						key:"pkVisitWay",
						value:"name",
						url:"api/visitway/query",
						params:function(){
							return {
								fetchProperties:"pkVisitWay,name"
							};
						},
						validate:["required"]
					},{
						label:"销售顾问",
						name:"saleConsultantName",
 						defaultValue:activeUser.name,
 						readonly:true
					},{
						name:"saleConsultant",
						type:"hidden",
 						defaultValue:activeUser.pkUser,
					},{
						label:"状态",
						name:"status",
						type:"select",
						defaultValue:"Intention",
						readonly:true,
						options:enmu["com.eling.elcms.travel.model.Customer.Status"],
					},{
						name:"contents",
						type:"textarea",
						label:"沟通内容",
						height:100,
						exValidate: function(value){
							if(value.length > 255){
								return "沟通内容不能大于255个字符！";
							}else{
								return true;
							}
						},
					},{
						name:"description",
						type:"textarea",
						label:"备注",
						exValidate: function(value){
							if(value.length > 255){
								return "备注不能大于255个字符！";
							}else{
								return true;
							}
						},
					}]
				 }
       	 });
       	 widget.set("form",form);
        }
    };
    module.exports = instance;
});
